//
//  ZpStatusCell.m
//  WeiBo_OC
//
//  Created by MacBook Pro on 16/5/29.
//  Copyright © 2016年 MacBook Pro. All rights reserved.
//

#import "ZpStatusCell.h"
#import "ZpStatusToolBar.h"
#import "ZpStatusOriginalView.h"
#import "ZpStatusRetweetedView.h"
@interface ZpStatusCell ()

@property (nonatomic, weak) UIImage *icon;
@property (nonatomic, strong) ZpStatusToolBar *toolBar;
@property (nonatomic, strong) ZpStatusRetweetedView *retweetedView;
@property (nonatomic, strong) ZpStatusOriginalView *originalView;
@property (nonatomic, weak) MASConstraint *constraint;
@end
@implementation ZpStatusCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setUIData{
    self.toolBar.status = self.statusViewModel.status;
    self.originalView.statusViewModel = self.statusViewModel;
    
    if (self.statusViewModel.status.retweeted_status) {
        self.retweetedView.retweeted_status = self.statusViewModel;

        [self.constraint uninstall];
        [self.toolBar updateConstraints:^(MASConstraintMaker *make) {
          self.constraint = make.top.equalTo(self.retweetedView.bottom);
        }];
    }else{
        [self.constraint uninstall];
        [self.toolBar updateConstraints:^(MASConstraintMaker *make) {
            self.constraint = make.top.equalTo(self.originalView.bottom);
        }];
    }
    
}

- (void)setStatusViewModel:(ZpStatusViewModel *)statusViewModel{
    _statusViewModel = statusViewModel;
    
    [self setUIData];
    
    [self.originalView makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.contentView);
    }];
    
    [self.retweetedView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.originalView.bottom);
        make.left.right.equalTo(self.contentView);
        
    }];
    
    [self.toolBar makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.height.equalTo(37);
    }];
    
    [self.contentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.bottom.equalTo(self.toolBar.bottom);
    }];
}


-(ZpStatusToolBar *)toolBar{
    if (!_toolBar) {
        _toolBar = [[ZpStatusToolBar alloc] init];
        [self.contentView addSubview:_toolBar];
    }
    return _toolBar;
}

-(ZpStatusOriginalView *)originalView{
    if (!_originalView) {
        _originalView = [[ZpStatusOriginalView alloc] init];
        [self.contentView addSubview:_originalView];
    }
    return _originalView;
}

-(ZpStatusRetweetedView *)retweetedView{
    if (!_retweetedView) {
        _retweetedView = [[ZpStatusRetweetedView alloc] init];
        [self.contentView addSubview:_retweetedView];
    }
    return _retweetedView;
}


@end
